﻿using Koala.Pro.Common;
using Koala.Pro.Common.Extension;
using Koala.Pro.Core.Dto;
using Koala.Pro.Core.Models;
using Koala.Pro.Services;

namespace Koala.Pro.ViewModels
{
    public class OperationLogSettingEditViewModel : BaseEditViewModel<OperationLogSettingInfo, string, OperationLogSettingPagedDto>
    {
        public OperationLogSettingEditViewModel(IOperationLogSettingService service)
            : base(service)
        {
            base.Title = "记录操作日志的数据表配置";
        }

        protected override async Task<bool> InsertOrUpdate()
        {
            if (base.IsEdit)
            {
                return await base.InsertOrUpdate();
            }
            List<string> list = base.Item.TableName.ToDelimitedList<string>(",");
            bool flag;
            if (list.Count > 1)
            {
                List<OperationLogSettingInfo> list2 = new List<OperationLogSettingInfo>();
                foreach (string item in list)
                {
                    OperationLogSettingInfo operationLogSettingInfo = new OperationLogSettingInfo
                    {
                        TableName = item,
                        Note = base.Item.Note,
                        Forbid = base.Item.Forbid,
                        InsertLog = base.Item.InsertLog,
                        UpdateLog = base.Item.UpdateLog,
                        DeleteLog = base.Item.DeleteLog,
                        CreateTime = DateTime.Now,
                        Creator = App.ViewModel.UserInfo.FullName,
                        Creator_ID = App.ViewModel.UserInfo.Id.ToString()
                    };
                    list2.Add(operationLogSettingInfo);
                }
                flag = await BLLFactory<IOperationLogSettingService>.Instance.InsertRangeAsync(list2);
            }
            else
            {
                base.Item.Creator = App.ViewModel.UserInfo.FullName;
                base.Item.Creator_ID = App.ViewModel.UserInfo.Id.ToString();
                base.Item.CreateTime = DateTime.Now;
                flag = await BLLFactory<IOperationLogSettingService>.Instance.InsertAsync(base.Item);
            }
            return flag;
        }

        public async Task InitData(string id)
        {
        }
    }
}
